﻿// CSystemSetDlg.cpp: 实现文件
//

#include "pch.h"
#include "RTOC-Data-Interface.h"
#include "CSystemSetDlg.h"
#include "afxdialogex.h"


// CSystemSetDlg 对话框

IMPLEMENT_DYNAMIC(CSystemSetDlg, CDialogEx)

CSystemSetDlg::CSystemSetDlg(CWnd* pParent /*=nullptr*/)
	: CDialogEx(IDD_SYSSETDLG, pParent)
	, m_strURL4(_T(""))
{

}

CSystemSetDlg::~CSystemSetDlg()
{
}

void CSystemSetDlg::DoDataExchange(CDataExchange* pDX)
{
	CDialogEx::DoDataExchange(pDX);
	DDX_Text(pDX, IDC_CLIENTID, m_strClientID);
	DDX_Text(pDX, IDC_BC, m_strBC);
	DDX_Text(pDX, IDC_MNAME, m_strMName);
	DDX_Text(pDX, IDC_MUSR, m_strMUsr);
	DDX_Text(pDX, IDC_MPWD, m_strMPwd);
	DDX_Text(pDX, IDC_YNAME, m_strYName);
	DDX_Text(pDX, IDC_YUSR, m_strYUsr);
	DDX_Text(pDX, IDC_YPWD, m_strYPwd);
	DDX_Text(pDX, IDC_KNAME, m_strKName);
	DDX_Text(pDX, IDC_KUSR, m_strKUsr);
	DDX_Text(pDX, IDC_KPWD, m_strKPwd);
	DDX_Text(pDX, IDC_RIP, m_strRIP);
	DDX_Text(pDX, IDC_RPORT, m_nRPort);
	DDX_Text(pDX, IDC_RPWD, m_strRPwd);
	DDX_Text(pDX, IDC_URL1, m_strURL1);
	DDX_Text(pDX, IDC_URL2, m_strURL2);
	DDX_Text(pDX, IDC_TIMESPAN, m_nTimeSpan);
	DDX_Text(pDX, IDC_URL4, m_strURL4);
}


BEGIN_MESSAGE_MAP(CSystemSetDlg, CDialogEx)
	ON_BN_CLICKED(IDOK, &CSystemSetDlg::OnBnClickedOk)
END_MESSAGE_MAP()


// CSystemSetDlg 消息处理程序


BOOL CSystemSetDlg::OnInitDialog()
{
	CDialogEx::OnInitDialog();

	// TODO:  在此添加额外的初始化
	m_strClientID = ReadINI(_T("SYSTEM"), _T("ClientID"));
	m_strBC = ReadINI(_T("SYSTEM"), _T("AuthCode"));
	m_strRIP = ReadINI(_T("SYSTEM"), _T("RedisIP"));
	m_nRPort = _wtol(ReadINI(_T("SYSTEM"), _T("RedisPort")));
	m_strRPwd = ReadINI(_T("SYSTEM"), _T("RedisPwd"));
	m_strMName = ReadINI(_T("SYSTEM"), _T("MasterDbName"));
	m_strMUsr = ReadINI(_T("SYSTEM"), _T("MasterDbUsr"));
	m_strMPwd = ReadINI(_T("SYSTEM"), _T("MasterDbPwd"));
	m_strYName = ReadINI(_T("SYSTEM"), _T("YQHDbName"));
	m_strYUsr = ReadINI(_T("SYSTEM"), _T("YQHDbUsr"));
	m_strYPwd = ReadINI(_T("SYSTEM"), _T("YQHDbPwd"));
	m_strKName = ReadINI(_T("SYSTEM"), _T("KdDbName"));
	m_strKUsr = ReadINI(_T("SYSTEM"), _T("KdDbUsr"));
	m_strKPwd = ReadINI(_T("SYSTEM"), _T("KdDbPwd"));
	m_strURL1 = gl.tlm.strURL1;
	m_strURL2 = gl.tlm.strURL2;
	m_strURL4 = gl.tlm.strURL4;
	m_nTimeSpan = gl.m_nTimeSpan;
	m_nToMaster = _wtol(ReadINI(_T("SYSTEM"), _T("ToMasterDb")));
	m_nToYqh = _wtol(ReadINI(_T("SYSTEM"), _T("ToYqhDb")));
	m_nToYqhUrl = _wtol(ReadINI(_T("SYSTEM"), _T("ToYqhUrl")));
	m_nToKd = _wtol(ReadINI(_T("SYSTEM"), _T("ToKdDb")));
	m_nToRedis = _wtol(ReadINI(_T("SYSTEM"), _T("ToRedis")));

	if (m_nToMaster == 1)
		((CButton*)GetDlgItem(IDC_CHECK1))->SetCheck(1);
	else
		((CButton*)GetDlgItem(IDC_CHECK1))->SetCheck(0);
	if (m_nToYqh == 1)
		((CButton*)GetDlgItem(IDC_CHECK2))->SetCheck(1);
	else
		((CButton*)GetDlgItem(IDC_CHECK2))->SetCheck(0);

	if (m_nToYqhUrl == 1)
		((CButton*)GetDlgItem(IDC_CHECK5))->SetCheck(1);
	else
		((CButton*)GetDlgItem(IDC_CHECK5))->SetCheck(0);

	if (m_nToKd == 1)
		((CButton*)GetDlgItem(IDC_CHECK3))->SetCheck(1);
	else
		((CButton*)GetDlgItem(IDC_CHECK3))->SetCheck(0);
	if (m_nToRedis == 1)
		((CButton*)GetDlgItem(IDC_CHECK4))->SetCheck(1);
	else
		((CButton*)GetDlgItem(IDC_CHECK4))->SetCheck(0);


	UpdateData(FALSE);
	return TRUE;  // return TRUE unless you set the focus to a control
				  // 异常: OCX 属性页应返回 FALSE
}


void CSystemSetDlg::OnBnClickedOk()
{
	// TODO: 在此添加控件通知处理程序代码
	UpdateData(TRUE);
	if (((CButton*)GetDlgItem(IDC_CHECK1))->GetCheck()==1)
		m_nToMaster = 1;
	else
		m_nToMaster = 0;
	if (((CButton*)GetDlgItem(IDC_CHECK2))->GetCheck() == 1)
		m_nToYqh=1;
	else
		m_nToYqh=0;
	if (((CButton*)GetDlgItem(IDC_CHECK3))->GetCheck() == 1)
		m_nToKd=1;
	else
		m_nToKd=0;
	if (((CButton*)GetDlgItem(IDC_CHECK4))->GetCheck() == 1)
		m_nToRedis=1;
	else
		m_nToRedis=0;

	if (((CButton*)GetDlgItem(IDC_CHECK5))->GetCheck() == 1)
		m_nToYqhUrl = 1;
	else
		m_nToYqhUrl = 0;
		
	if (m_nTimeSpan < 1 || m_nTimeSpan>120)
		m_nTimeSpan = 10;

	SaveINI(_T("SYSTEM"), _T("ClientID"), m_strClientID);
	SaveINI(_T("SYSTEM"), _T("AuthCode"), m_strBC);
	SaveINI(_T("SYSTEM"), _T("RedisIP"), m_strRIP);
	SaveINI(_T("SYSTEM"), _T("RedisPort"), m_nRPort);
	SaveINI(_T("SYSTEM"), _T("RedisPwd"), m_strRPwd);
	SaveINI(_T("SYSTEM"), _T("MasterDbName"), m_strMName);
	SaveINI(_T("SYSTEM"), _T("MasterDbUsr"), m_strMUsr);
	SaveINI(_T("SYSTEM"), _T("MasterDbPwd"), m_strMPwd);
	SaveINI(_T("SYSTEM"), _T("YQHDbName"), m_strYName);
	SaveINI(_T("SYSTEM"), _T("YQHDbUsr"), m_strYUsr);
	SaveINI(_T("SYSTEM"), _T("YQHDbPwd"), m_strYPwd);
	SaveINI(_T("SYSTEM"), _T("KdDbName"), m_strKName);
	SaveINI(_T("SYSTEM"), _T("KdDbUsr"), m_strKUsr);
	SaveINI(_T("SYSTEM"), _T("KdDbPwd"), m_strKPwd);
	SaveINI(_T("SYSTEM"), _T("TimeSpan"), m_nTimeSpan);

	SaveINI(_T("SYSTEM"), _T("ToMasterDb"), m_nToMaster);
	SaveINI(_T("SYSTEM"), _T("ToYqhDb"), m_nToYqh);
	SaveINI(_T("SYSTEM"), _T("ToYqhUrl"), m_nToYqhUrl);
	SaveINI(_T("SYSTEM"), _T("ToKdDb"), m_nToKd);
	SaveINI(_T("SYSTEM"), _T("ToRedis"), m_nToRedis);

	gl.tlm.strURL1=m_strURL1;
	gl.tlm.strURL2=m_strURL2;
	gl.tlm.strURL4=m_strURL4;
	gl.m_nTimeSpan=m_nTimeSpan;

	gl.SaveWellsCfg();
	CDialogEx::OnOK();
}
